import pandas as pd
import numpy as np
from numpy import array
import math
from itertools import combinations
from functools import reduce
import datetime
from datetime import datetime, timedelta

from tabulate import tabulate
import time
default_year = 2024
df_out = pd.DataFrame(columns=['TIME', 'ORDER'])
for i in range(11, 25):
    # if i in [16, 17, 23, 24]:
    # if i not in [16, 17, 23, 24]:
    # if i not in [11, 12, 13, 14, 15]:
    # if i not in [18, 19, 20, 21, 22]:
    # if i not in [16, 17]:
    # if i not in [23, 24]:
    #     continue
    date_str = '11.' + str(i)
    date_parts = date_str.split('.')
    if len(date_parts) == 2:  # 如果只有月日
        date_parts.insert(0, str(default_year))
    csv_name = 'D:/repos/sicost/流量B/新建文件夹/' + date_str +'.csv'
    print(csv_name)
    # csv_name = 'D:/repos/sicost/流量/新建文件夹/11.16.csv'
    df_0 = pd.read_csv(csv_name)
    df_0.rename(columns={'x_st per minute': 'MINUTE'}, inplace=True)
    def __cal_time(x):
        time_str = x.MINUTE
        time_parts = time_str.split(':')
        datetime_obj = datetime(int(date_parts[0]), int(date_parts[1]), int(date_parts[2]),
                                int(time_parts[0]), int(time_parts[1]))
        rst = datetime_obj.strftime('%Y-%m-%d %H:%M:%S')
        # print(rst)
        return rst
    df_0['TIME'] = df_0.apply(lambda x: __cal_time(x), axis=1)
    df_0.drop(['MINUTE'], axis=1, inplace=True)
    # df_0['Count'] = df_0['Count'].str.replace(',', '').astype(int)
    # df_0['Count'] = df_0['Count'].astype(int)
    try:
        df_0['Count'] = df_0['Count'].str.replace(',', '').astype(int)
    except Exception as e:
        df_0['Count'] = df_0['Count'].astype(int)
    df_0['ORDER'] = df_0['Count'] * 11
    df_0.drop(['Count'], axis=1, inplace=True)


    df_out = pd.concat([df_out, df_0], axis=0)
    df_out = df_out.reset_index(drop=True)
df_out = df_out.sort_values(by=["TIME"], ascending=True)
df_out = df_out.reset_index(drop=True)
writer = pd.ExcelWriter('新数据6.xlsx')
df_out.to_excel(writer, sheet_name='Sheet1', index=False)
writer.save()
print('finish')









